package com.business_clean.ui.adapter.todo;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.business_clean.R;
import com.business_clean.app.uitl.ActivityForwardUtil;
import com.business_clean.data.mode.todo.TodoItemList;
import com.business_clean.ui.activity.todo.TodoDetailActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;

public class TodoAdapter extends BaseQuickAdapter<TodoItemList, BaseViewHolder> {

    private boolean hideBottom = false;

    public TodoAdapter(boolean hide) {
        super(R.layout.item_todo);
        this.hideBottom = hide;
        addChildClickViewIds(R.id.but_item_refuse, R.id.but_item_agree, R.id.but_item_withdraw, R.id.but_item_del);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, TodoItemList item) {
        holder.setText(R.id.tv_item_todo_status, item.getApplication_status_name())
                .setText(R.id.tv_item_todo_date, item.getCreate_time())
                .setText(R.id.tv_item_todo_title, item.getApplication_title());


        //隐藏底部按钮
        holder.getView(R.id.ll_item_todo_bottom_layout).setVisibility(hideBottom ? View.GONE : View.VISIBLE);

        RecyclerView recyclerView = holder.getView(R.id.recyclerview_item_todo);
        recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
        TodoItemAdapter itemAdapter = new TodoItemAdapter();
        recyclerView.setAdapter(itemAdapter);
        itemAdapter.setList(item.getSummary_list());

        itemAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                Bundle bundle = new Bundle();
                bundle.putString("application_type", "" + getData().get(getItemPosition(item)).getApplication_type());
                bundle.putString("application_no", "" + getData().get(getItemPosition(item)).getApplication_no());
                ActivityForwardUtil.startActivity(TodoDetailActivity.class, bundle);
            }
        });

        TextView del = holder.getView(R.id.but_item_del);//删除
        TextView withdraw = holder.getView(R.id.but_item_withdraw);//撤回
        TextView refuse = holder.getView(R.id.but_item_refuse);//拒绝
        TextView agree = holder.getView(R.id.but_item_agree);//同意
        TextView textView = holder.getView(R.id.tv_item_todo_status);

        switch (item.getApplication_status()) {//0是待完善 1审批中 2已通过 3已拒绝 4已撤回
            case "0"://待完善
                textView.setTextColor(Color.parseColor("#800080"));
                agree.setText("完善");
                del.setVisibility(View.VISIBLE);
                agree.setVisibility(View.VISIBLE);
                refuse.setVisibility(View.GONE);
                withdraw.setVisibility(View.GONE);
                break;
            case "1"://审批中
                agree.setText("同意");
                refuse.setText("拒绝");
                agree.setVisibility(View.VISIBLE);
                refuse.setVisibility(View.VISIBLE);
                del.setVisibility(View.GONE);
                withdraw.setVisibility(View.GONE);
                textView.setTextColor(Color.parseColor("#F4A460"));
                break;
            case "2"://已通过
                agree.setVisibility(View.GONE);
                del.setVisibility(View.GONE);
                withdraw.setVisibility(View.GONE);
                refuse.setVisibility(View.GONE);
                textView.setTextColor(Color.parseColor("#09BE89"));
                break;
            case "3"://已拒绝
                agree.setText("重新提交");
                agree.setVisibility(View.VISIBLE);
                del.setVisibility(View.GONE);
                withdraw.setVisibility(View.GONE);
                refuse.setVisibility(View.GONE);
                textView.setTextColor(Color.parseColor("#DC143C"));
                break;
            case "4"://已撤回
                agree.setText("重新提交");
                agree.setVisibility(View.VISIBLE);
                del.setVisibility(View.GONE);
                withdraw.setVisibility(View.GONE);
                refuse.setVisibility(View.GONE);
                textView.setTextColor(Color.parseColor("#8D8E99"));
                break;
        }
    }
}